package br.com.LeitorLog.gui.util;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public final class FileUtils {

	public FileUtils() { }

	public static byte[] getBytesFromFile(String file) throws IOException {
		return SerializationUtils.getBytesFromStream(SerializationUtils.createStream(file));
	}
	
	public static void writeFile(byte[] bytes, String file) throws IOException {
		FileOutputStream output = new FileOutputStream(file);
		SerializationUtils.copy(new ByteArrayInputStream(bytes), output);
	}
	
	public static void writeFile(byte[] bytes, File file) throws IOException {
		FileOutputStream output = new FileOutputStream(file);
		SerializationUtils.copy(new ByteArrayInputStream(bytes), output);
	}
	
	public static void copy(String from, String to) throws IOException {
		FileOutputStream output = new FileOutputStream(to);
		SerializationUtils.copy(SerializationUtils.createStream(from), output);
		output.close();
	}

}